#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
//http://oj33.cn/contest.php?cid=1075
//https://blog.csdn.net/qq_37482202/article/details/89513877
 int f[1000001];
int find(int x)
{
	if (f[x] != x)
	{
		f[x] = find(x);
	}
	return f[x];
}
int main()
{
	int n; 
	int q;
	cin >> n >> q;
	for (int i = 1; i <= n; i++)
	{
		f[i] = i;
	}int t = q;
	while (q--)
	{
		
		int u, v;
		cin >> u >> v;
		f[v] = u;
		
	}
	cin >> t;
	while (t--)
	{
		int u, v;
		cin >> u >> v;
			cout << (find(u) == find(v) ? "yes" : "no") << endl;
	}
	return 0;
}